/**
 * 游戏桌子
 */
class Table extends eui.Component {

	private parentContainer: eui.UILayer;
	private group_buttons: eui.Group;
	private group_cards: eui.Group;
	private roomId: number;
	private status:TableStatus;
	private currentPlayerSeat:Seat;
	private group_seats:eui.Group;
	private btn_back:eui.Button;

	
	/**
	 * 当前游戏玩家
	 */
	private currentPlayer: Player = null;

	/**
	 * 桌子
	 */
	public static currentTable: Table;

	public constructor(parent: eui.UILayer) {
		super();
		this.parentContainer = parent;
		this.skinName = "TableSkin";
		Table.currentTable = this;
		this.status = TableStatus.UnJoinGame;
		this.btn_back.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onBack,this);
	}

	private onBack():void{
		this.parentContainer.removeChild(this);
		this.parentContainer.addChild(new Home(this.parentContainer));
	}

	/**
	 * 获取游戏的桌子
	 */
	public static getTable(): Table {
		return Table.currentTable;
	}

	/**
	 * 查找参与游戏的玩家
	 */
	public findPlayer(playerId: number): Player {
		//TODO 查找玩家
		return null;
	}

	/**
	 * 查找玩家的座位
	 */
	public findPlayerSeat(playerId:number):Seat{
		//TODO 查找玩家的座位
		return null;
	}

	/**
	 * 定义桌子的位置及当前主要玩家的座位
	 * 顺时针方向初始化座位
	 * 以当前玩家的需要开始编号，顺时针周期递增
	 */
	public initTable(): void {
		//TODO 初始化玩家
	}

	/**
	 * 发牌
	 */
	public deal(cards: Card[],delay:number): void {
		if (cards == null) return;
		let timer = new egret.Timer(delay,5);
		let i = 0;
		timer.addEventListener(egret.TimerEvent.TIMER,function(){
			let card = cards[i];
			this.group_cards.addChild(card);
			i++;
		},this);
		timer.start();
	}

	/**
	 * 翻牌
	 */
	public flop(): void {

	}

	/**
	 * 开始游戏
	 */
	public start():void{
		this.status = TableStatus.Waitting;
	}
}